import { Controller, Body, Get, Post, UseGuards, Request } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger'
import { UserLogin } from './dto'
import { WxUser, UserDocument } from '@libs/db/schemas/user.schema'
import { AuthService } from './auth.service'

@Controller('auth')
@ApiTags('验证')
export class AuthController {
  constructor(private readonly authService: AuthService) {}
  @Post('login')
  @ApiOperation({ summary: '登录取信息' })
  // -.-他喵的卡几个小时就是因为把装饰器写到外面去了
  @UseGuards(AuthGuard('local'))
  userLogin(@Body() userDto: UserLogin, @Request() res): WxUser {
    return res.user
  }

  @Get('getUser')
  @ApiOperation({ summary: '获取个人信息' })
  @ApiBearerAuth()
  @UseGuards(AuthGuard('jwt'))
  getUser(@Request() req) {
    return this.authService.getUserInfo(req.user.id)
  }
}
